package com.efeichong.project.domain.entity.db;

import com.efeichong.audit.InsertDefault;
import com.efeichong.audit.UpdateDefault;
import com.efeichong.common.config.AuditorHolder;
import com.efeichong.common.domain.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.List;


/**
 * @author
 * @date 2020/12/03
 * @description 岗位信息表
 */
@Setter
@Getter
@Entity
@Table(indexes = {
        @Index(name = "PRIMARY", columnList = "id", unique = true),
})
@DynamicInsert
@DynamicUpdate
public class SysPost extends BaseEntity {
    /**
     * 岗位编码
     */
    @Column(name = "[code]", columnDefinition = "varchar(64) not null comment'岗位编码'")
    private String code;

    /**
     * 岗位名称
     */
    @Column(name = "[name]", columnDefinition = "varchar(50) not null comment'岗位名称'")
    private String name;

    /**
     * 显示顺序
     */
    @Column(name = "[sort]", columnDefinition = "int default'0' comment'显示顺序'")
    private Integer sort;

    /**
     * 创建者
     */
    @InsertDefault(val = AuditorHolder.class)
    @JoinColumn(name = "[create_by]")
    @ManyToOne(fetch = FetchType.LAZY)
    private SysUser createBy;

    /**
     * 更新者
     */
    @UpdateDefault(val = AuditorHolder.class)
    @JoinColumn(name = "[update_by]")
    @ManyToOne(fetch = FetchType.LAZY)
    private SysUser updateBy;

    /**
     * 备注
     */
    @Column(name = "[remark]", columnDefinition = "varchar(255)  comment'备注'")
    private String remark;

    @InsertDefault("20")
    @Column(name = "[status]", nullable = false, precision = 20)
    private Long status;

    /**
     * 用户
     */
    @ManyToMany(fetch = FetchType.LAZY, mappedBy = "sysPosts")
    private List<SysUser> sysUsers;
}
